package cn.wx.scholar.neo4j.repository;

import java.util.List;

import org.neo4j.ogm.model.Result;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
/*import org.springframework.data.neo4j.repository.GraphRepository;*/
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import cn.wx.scholar.neo4j.entity.Org;

@Repository
public interface OrgRepository extends Neo4jRepository<Org,Long> {
	@Query("match(o:org)-[r:include]-(e:expert) where id(e)={id} return  distinct o")
	List<Org> getRelateOrg(@Param("id") Long id);	//查询某个专家相关的机构
	
	
	@Query(" match(o:org)-[r:include]-(e:expert) where (e.name=~ {name} or e.fos=~ {name} or e.authorsOrg=~ {name}) return  distinct o limit 50" )
	List<Org> findByQueryParam(@Param("name")String name);
	
	@Query("match(o:org)-[r:include]->(e:expert) where ID(e) IN {expertIds} return distinct ID(e) as eId,o.name as oName")
	Result getOrgByExpertIds(@Param("expertIds") List<Long> expertIds);
	
	/**
	 * @param expertIds
	 * @return
	 */
	@Query("match(o:org)-[r:include]->(e:expert) where ID(e) IN {expertIds} return distinct o")
	List<Org> getOrgByExpertIdsRe(@Param("expertIds") List<Long> expertIds);

}
